package it.polimi.traveldream.web.beans.administrator;

import java.util.List;


import it.polimi.traveldream.ejbclient.dtos.UserDTO;
import it.polimi.traveldream.ejbclient.eaos.AccountServiceEAO;
import it.polimi.traveldream.utils.enums.UserRole;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.application.ConfigurableNavigationHandler;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

import org.primefaces.event.SelectEvent;

@ManagedBean(name="listEmployees")
@SessionScoped
public class ListEmployeeBean {
	@EJB
	private AccountServiceEAO aService;
	private List<UserDTO> employees;
	private UserDTO selectedEmployee;
	
	public ListEmployeeBean() {
	}
	
	@PostConstruct
	public void init() {
		employees = aService.getUsers(UserRole.EMPLOYEE);
	}

	public List<UserDTO> getEmployees() {
		return employees;
	}
	
	public UserDTO getSelectedEmployee() {
		return selectedEmployee;  
	}  
	 
	public void setSelectedEmployee(UserDTO selectedEmployee) {
		this.selectedEmployee = selectedEmployee;  
	}
	
	public void onRowSelectNavigate(SelectEvent event) {
		FacesContext.getCurrentInstance().getExternalContext().getFlash().put("selectedEmployee", event.getObject());  
		ConfigurableNavigationHandler nh = (ConfigurableNavigationHandler)FacesContext.getCurrentInstance().getApplication().getNavigationHandler();
		nh.performNavigation("detailEmployee?faces-redirect=true"); 
    }
	
}
